﻿using System;

namespace Common
{
    public class ClassBrigade
    {
        public ClassBrigade() { }
        /// <summary>
        /// 编号
        /// </summary>
        public Guid Guid
        {
            get;
            set;
        }
        /// <summary>
        /// 全称
        /// </summary>
        public string FullName
        {
            get;
            set;
        }
        /// <summary>
        /// 省份
        /// </summary>
        public string Province
        {
            get;
            set;
        }
        /// <summary>
        /// 城市
        /// </summary>
        public string City
        {
            get;
            set;
        }
        /// <summary>
        /// 区县
        /// </summary>
        public string District
        {
            get;
            set;
        }
        /// <summary>
        /// 警队
        /// </summary>
        public string Brigade
        {
            get;
            set;
        }
        /// <summary>
        /// 字母代码
        /// </summary>
        public string Code
        {
            get;
            set;
        }
        /// <summary>
        /// 地址
        /// </summary>
        public string Address
        {
            get;
            set;
        }
        /// <summary>
        /// 邮编
        /// </summary>
        public string Postcode
        {
            get;
            set;
        }

        public override bool Equals(object obj)
        {
            var other = obj as ClassBrigade;
            return other != null && Coding2String() == other.Coding2String();
        }

        public override int GetHashCode()
        {
            return this.Coding2String().GetHashCode();
        }

        public static bool operator ==(ClassBrigade left, ClassBrigade right)
        {
            if(ReferenceEquals(left, right))
            {
                return true;
            }
            return left.Equals(right);
        }

        public static bool operator !=(ClassBrigade left, ClassBrigade right) => !(left == right);

        public string Coding2String()
        {
            string b = null;
            if (this.Guid == null)
            {
                return null;
            }
            b += this.Guid.ToString() + "♠";
            b += this.FullName + "♠";
            b += this.Province + "♠";
            b += this.City + "♠";
            b += this.District + "♠";
            b += this.Brigade + "♠";
            b += this.Code + "♠";
            b += this.Address + "♠";
            b += this.Postcode;
            return b;
        }

        public void DecodingFromString(string message)
        {
            string[] str = message.Split('♠');
            this.Guid = new Guid(str[0]);
            this.FullName = str[1];
            this.Province = str[2];
            this.City = str[3];
            this.District = str[4];
            this.Brigade = str[5];
            this.Code = str[6];
            this.Address = str[7];
            this.Postcode = str[8];
        }
    }
}
